package com.odais.mvc.seller;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ProgressBar;

import com.odais.R;
import com.odais.DataManagement.DataListener;
import com.odais.DataManagement.DataManager;
import com.odais.Reservation.ReservationList;

/**
 *
 * @author Lionel DECELLE
 * @since 8 juin 2012 - 10:54:15
 *
 */
public class sellerListViewHist extends ListActivity{


	protected ProgressBar mProgressBar;

    private sellerListViewPendingLVAdapter m_adapter;
    private ReservationList reservationArrayList;
	private DataManager dataManager;


	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.sellerlistviewpending);
    	reservationArrayList = new ReservationList();
		dataManager = new DataManager(this);

        m_adapter = new sellerListViewPendingLVAdapter(this, dataManager, R.layout.sellerlistviewpending_list, reservationArrayList);
        setListAdapter(m_adapter);
		dataManager.UpdateReservationList(DataManager.UPDATE_TYPE_CONFIRMED_LIST);
        
        
    	DataListener dataListener = new DataListener()
    	{
			@Override
			public void onDataUpdate(ReservationList reservationArrayListUpdated)
			{
				//Catch confirmed list
				if(reservationArrayListUpdated.getListType().equals(DataManager.UPDATE_TYPE_CONFIRMED_LIST))
				{	
	    			reservationArrayList = reservationArrayListUpdated;
	    			m_adapter.Update(reservationArrayList);
	    			
	    			runOnUiThread(new Runnable() 
	    			{
	                    public void run()
	                    {
	                    	m_adapter.clear();
	    	                for(int i=0;i<reservationArrayList.size();i++)
	    	                {
	    	                	m_adapter.add(reservationArrayList.get(i));
	                			m_adapter.notifyDataSetChanged();
	                    	}
	                    }
	                });
				}
    		}
    	};
    	
    	DataManager.setOnDataUpdateListener(dataListener);

    }

}